<template>
  <div>
    <iframe ref="openWebUI" :src="srcUrl" frameborder="0" style="width: 99%;height: 85vh" @load="onIframeLoad"></iframe>
  </div>
</template>

<script>

export default {
  name: "Ai",
  data(){
    return {
      srcUrl: 'http://ai.sangu.js.cn:3000/'
      ,authCookieName: 'token'
      ,authCookieValue: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjY5NzkyZGE1LTRiOTUtNDIyZS1hNWQwLTIzYjI3MWUwNDQ4YyJ9.inHg_us_XX98pybQn2rxUTnuuusgwmjEvAcpKayJAxU'
    }
  },
  created() {
    // this.load();
  },
  mounted() {
    this.setAuthCookie()
  },
  methods: {
    setAuthCookie(){
      // 设置一个名为 'authToken' 的 cookie，值为 'your-auth-token-here'
      // 注意：这里假设你的主网页和内置网页位于相同的域或能够共享 cookies
      // document.cookie = `${this.authCookieName}=${encodeURIComponent(this.authCookieValue)}; Path=/; SameSite=None; Secure`;

      // 如果你的内置网页位于不同的子域，你可能还需要设置 Domain 属性
      document.cookie = `${this.authCookieName}=${encodeURIComponent(this.authCookieValue)}; Path=/; Domain=.*.sangu.js.cn; SameSite=None; Secure`;
    },
    onIframeLoad(){
      this.autoLogin();
    },
    autoLogin(){
      const iframe = this.$refs.openWebUI.contentWindow;
      console.log(iframe)
    }

  }
}
</script>

<style>
</style>